<?xml version="1.0" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><link href="http://search.cpan.org/s/style.css" rel="stylesheet" type="text/css">
<title>MagneticField(1)</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<link rev="made" href="mailto:root@localhost" />
</head>

<body>



<h1 id="NAME">NAME</h1>

<p>MagneticField -- compute the earth&#39;s magnetic field</p>

<h1 id="SYNOPSIS">SYNOPSIS</h1>

<p><b>MagneticField</b> [ <b>-n</b> <i>name</i> ] [ <b>-d</b> <i>dir</i> ] [ <b>-N</b> <i>Nmax</i> ] [ <b>-M</b> <i>Mmax</i> ] [ <b>-t</b> <i>time</i> | <b>-c</b> <i>time</i> <i>lat</i> <i>h</i> ] [ <b>-r</b> ] [ <b>-w</b> ] [ <b>-T</b> <i>tguard</i> ] [ <b>-H</b> <i>hguard</i> ] [ <b>-p</b> <i>prec</i> ] [ <b>-v</b> ] [ <b>--comment-delimiter</b> <i>commentdelim</i> ] [ <b>--version</b> | <b>-h</b> | <b>--help</b> ] [ <b>--input-file</b> <i>infile</i> | <b>--input-string</b> <i>instring</i> ] [ <b>--line-separator</b> <i>linesep</i> ] [ <b>--output-file</b> <i>outfile</i> ]</p>

<h1 id="DESCRIPTION">DESCRIPTION</h1>

<p><b>MagneticField</b> reads in times and positions on standard input and prints out the geomagnetic field on standard output and, optionally, its rate of change.</p>

<p>The input line is of the form <i>time</i> <i>lat</i> <i>lon</i> <i>h</i>. <i>time</i> is a date of the form 2012-07-03, a fractional year such as 2012.5, or the string &quot;now&quot;. <i>lat</i> and <i>lon</i> are the latitude and longitude expressed as decimal degrees or degrees, minutes, and seconds; for details on the allowed formats for latitude and longitude, see the <code>GEOGRAPHIC COORDINATES</code> section of GeoConvert(1). <i>h</i> is the height above the ellipsoid in meters; this is optional and defaults to zero. Alternatively, <i>time</i> can be given on the command line as the argument to the <b>-t</b> option, in which case it should not be included on the input lines. Finally, the magnetic field can be computed at various points on a circle of latitude (constant <i>time</i>, <i>lat</i>, and <i>h</i>) via the <b>-c</b> option; in this case only the longitude should be given on the input lines.</p>

<p>The output consists of the following 7 items:</p>

<pre><code>  the declination (the direction of the horizontal component of
    the magnetic field measured clockwise from north) in degrees,
  the inclination (the direction of the magnetic field measured
    down from the horizontal) in degrees,
  the horizontal field in nanotesla (nT),
  the north component of the field in nT,
  the east component of the field in nT,
  the vertical component of the field in nT (down is positive),
  the total field in nT.</code></pre>

<p>If the <b>-r</b> option is given, a second line is printed giving the rates of change of these quantities in degrees/yr and nT/yr.</p>

<p>The WGS84 ellipsoid is used, <i>a</i> = 6378137 m, <i>f</i> = 1/298.257223563.</p>

<h1 id="OPTIONS">OPTIONS</h1>

<dl>

<dt id="n-name"><b>-n</b> <i>name</i></dt>
<dd>

<p>use magnetic field model <i>name</i> instead of the default <code>wmm2015v2</code>. See <a href="#MODELS">&quot;MODELS&quot;</a>.</p>

</dd>
<dt id="d-dir"><b>-d</b> <i>dir</i></dt>
<dd>

<p>read magnetic models from <i>dir</i> instead of the default. See <a href="#MODELS">&quot;MODELS&quot;</a>.</p>

</dd>
<dt id="N-Nmax"><b>-N</b> <i>Nmax</i></dt>
<dd>

<p>limit the degree of the model to <i>Nmax</i>.</p>

</dd>
<dt id="M-Mmax"><b>-M</b> <i>Mmax</i></dt>
<dd>

<p>limit the order of the model to <i>Mmax</i>.</p>

</dd>
<dt id="t-time"><b>-t</b> <i>time</i></dt>
<dd>

<p>evaluate the field at <i>time</i> instead of reading the time from the input lines.</p>

</dd>
<dt id="c-time-lat-h"><b>-c</b> <i>time</i> <i>lat</i> <i>h</i></dt>
<dd>

<p>evaluate the field on a circle of latitude given by <i>time</i>, <i>lat</i>, <i>h</i> instead of reading these quantities from the input lines. In this case, <b>MagneticField</b> can calculate the field considerably more quickly.</p>

</dd>
<dt id="r"><b>-r</b></dt>
<dd>

<p>toggle whether to report the rates of change of the field.</p>

</dd>
<dt id="w"><b>-w</b></dt>
<dd>

<p>toggle the longitude first flag (it starts off); if the flag is on, then on input and output, longitude precedes latitude (except that, on input, this can be overridden by a hemisphere designator, <i>N</i>, <i>S</i>, <i>E</i>, <i>W</i>).</p>

</dd>
<dt id="T-tguard"><b>-T</b> <i>tguard</i></dt>
<dd>

<p>signal an error if <i>time</i> lies <i>tguard</i> years (default 50 yr) beyond the range for the model.</p>

</dd>
<dt id="H-hguard"><b>-H</b> <i>hguard</i></dt>
<dd>

<p>signal an error if <i>h</i> lies <i>hguard</i> meters (default 500000 m) beyond the range for the model.</p>

</dd>
<dt id="p-prec"><b>-p</b> <i>prec</i></dt>
<dd>

<p>set the output precision to <i>prec</i> (default 1). Fields are printed with precision with <i>prec</i> decimal places; angles use <i>prec</i> + 1 places.</p>

</dd>
<dt id="v"><b>-v</b></dt>
<dd>

<p>print information about the magnetic model on standard error before processing the input.</p>

</dd>
<dt id="comment-delimiter-commentdelim"><b>--comment-delimiter</b> <i>commentdelim</i></dt>
<dd>

<p>set the comment delimiter to <i>commentdelim</i> (e.g., &quot;#&quot; or &quot;//&quot;). If set, the input lines will be scanned for this delimiter and, if found, the delimiter and the rest of the line will be removed prior to processing and subsequently appended to the output line (separated by a space).</p>

</dd>
<dt id="version"><b>--version</b></dt>
<dd>

<p>print version and exit.</p>

</dd>
<dt id="h"><b>-h</b></dt>
<dd>

<p>print usage, the default magnetic path and name, and exit.</p>

</dd>
<dt id="help"><b>--help</b></dt>
<dd>

<p>print full documentation and exit.</p>

</dd>
<dt id="input-file-infile"><b>--input-file</b> <i>infile</i></dt>
<dd>

<p>read input from the file <i>infile</i> instead of from standard input; a file name of &quot;-&quot; stands for standard input.</p>

</dd>
<dt id="input-string-instring"><b>--input-string</b> <i>instring</i></dt>
<dd>

<p>read input from the string <i>instring</i> instead of from standard input. All occurrences of the line separator character (default is a semicolon) in <i>instring</i> are converted to newlines before the reading begins.</p>

</dd>
<dt id="line-separator-linesep"><b>--line-separator</b> <i>linesep</i></dt>
<dd>

<p>set the line separator character to <i>linesep</i>. By default this is a semicolon.</p>

</dd>
<dt id="output-file-outfile"><b>--output-file</b> <i>outfile</i></dt>
<dd>

<p>write output to the file <i>outfile</i> instead of to standard output; a file name of &quot;-&quot; stands for standard output.</p>

</dd>
</dl>

<h1 id="MODELS">MODELS</h1>

<p><b>MagneticField</b> computes the geomagnetic field using one of the following models</p>

<pre><code>    wmm2010, the World Magnetic Model 2010, which approximates the
      main magnetic field for the period 2010-2015.  See
      https://ngdc.noaa.gov/geomag/WMM/DoDWMM.shtml
    wmm2015v2, the World Magnetic Model 2015, which approximates the
      main magnetic field for the period 2015-2020.  See
      https://ngdc.noaa.gov/geomag/WMM/DoDWMM.shtml
    wmm2015, a deprecated version of wmm2015v2
    igrf11, the International Geomagnetic Reference Field (11th
      generation), which approximates the main magnetic field for
      the period 1900-2015.  See
      https://ngdc.noaa.gov/IAGA/vmod/igrf.html
    igrf12, the International Geomagnetic Reference Field (12th
      generation), which approximates the main magnetic field for
      the period 1900-2020.  See
      https://ngdc.noaa.gov/IAGA/vmod/igrf.html
    emm2010, the Enhanced Magnetic Model 2010, which approximates
      the main and crustal magnetic fields for the period 2010-2015.
      See https://ngdc.noaa.gov/geomag/EMM/index.html
    emm2015, the Enhanced Magnetic Model 2015, which approximates
      the main and crustal magnetic fields for the period 2000-2020.
      See https://ngdc.noaa.gov/geomag/EMM/index.html
    emm2017, the Enhanced Magnetic Model 2017, which approximates
      the main and crustal magnetic fields for the period 2000-2022.
      See https://ngdc.noaa.gov/geomag/EMM/index.html</code></pre>

<p>These models approximate the magnetic field due to the earth&#39;s core and (in the case of emm20xx) its crust. They neglect magnetic fields due to the ionosphere, the magnetosphere, nearby magnetized materials, electrical machinery, etc.</p>

<p>By default, the <code>wmm2015v2</code> magnetic model is used. This may changed by setting the environment variable <code>GEOGRAPHICLIB_MAGNETIC_NAME</code> or with the <b>-n</b> option.</p>

<p>The magnetic models will be loaded from a directory specified at compile time. This may changed by setting the environment variables <code>GEOGRAPHICLIB_MAGNETIC_PATH</code> or <code>GEOGRAPHICLIB_DATA</code>, or with the <b>-d</b> option. The <b>-h</b> option prints the default magnetic path and name. Use the <b>-v</b> option to ascertain the full path name of the data file.</p>

<p>Instructions for downloading and installing magnetic models are available at <a href="https://geographiclib.sourceforge.io/html/magnetic.html#magneticinst">https://geographiclib.sourceforge.io/html/magnetic.html#magneticinst</a>.</p>

<h1 id="ENVIRONMENT">ENVIRONMENT</h1>

<dl>

<dt id="GEOGRAPHICLIB_MAGNETIC_NAME"><b>GEOGRAPHICLIB_MAGNETIC_NAME</b></dt>
<dd>

<p>Override the compile-time default magnetic name of <code>wmm2015v2</code>. The <b>-h</b> option reports the value of <b>GEOGRAPHICLIB_MAGNETIC_NAME</b>, if defined, otherwise it reports the compile-time value. If the <b>-n</b> <i>name</i> option is used, then <i>name</i> takes precedence.</p>

</dd>
<dt id="GEOGRAPHICLIB_MAGNETIC_PATH"><b>GEOGRAPHICLIB_MAGNETIC_PATH</b></dt>
<dd>

<p>Override the compile-time default magnetic path. This is typically <code>/usr/local/share/GeographicLib/magnetic</code> on Unix-like systems and <code>C:/ProgramData/GeographicLib/magnetic</code> on Windows systems. The <b>-h</b> option reports the value of <b>GEOGRAPHICLIB_MAGNETIC_PATH</b>, if defined, otherwise it reports the compile-time value. If the <b>-d</b> <i>dir</i> option is used, then <i>dir</i> takes precedence.</p>

</dd>
<dt id="GEOGRAPHICLIB_DATA"><b>GEOGRAPHICLIB_DATA</b></dt>
<dd>

<p>Another way of overriding the compile-time default magnetic path. If it is set (and if <b>GEOGRAPHICLIB_MAGNETIC_PATH</b> is not set), then $<b>GEOGRAPHICLIB_DATA</b>/magnetic is used.</p>

</dd>
</dl>

<h1 id="ERRORS">ERRORS</h1>

<p>An illegal line of input will print an error message to standard output beginning with <code>ERROR:</code> and causes <b>MagneticField</b> to return an exit code of 1. However, an error does not cause <b>MagneticField</b> to terminate; following lines will be converted. If <i>time</i> or <i>h</i> are outside the recommended ranges for the model (but inside the ranges increase by <i>tguard</i> and <i>hguard</i>), a warning is printed on standard error and the field (which may be inaccurate) is returned in the normal way.</p>

<h1 id="EXAMPLES">EXAMPLES</h1>

<p>The magnetic field from WMM2015v2 in Timbuktu on 2016-01-01</p>

<pre><code>    echo 2016-01-01 16:46:33N 3:00:34W 300 | MagneticField -r
    =&gt; -2.10 12.14 33877.0 33854.2 -1242.7 7289.6 34652.4
       0.12 -0.04 26.1 28.8 72.4 -21.3 21.0</code></pre>

<p>The first two numbers returned are the declination and inclination of the field. The second line gives the annual change.</p>

<h1 id="SEE-ALSO">SEE ALSO</h1>

<p>GeoConvert(1), geographiclib-get-magnetic(8).</p>

<h1 id="AUTHOR">AUTHOR</h1>

<p><b>MagneticField</b> was written by Charles Karney.</p>

<h1 id="HISTORY">HISTORY</h1>

<p><b>MagneticField</b> was added to GeographicLib, <a href="https://geographiclib.sourceforge.io">https://geographiclib.sourceforge.io</a>, in version 1.15.</p>


</body>

</html>


